package impl

import (
	"context"
	"github.com/starmotioncf/soutchatinternal/model"
	"github.com/starmotioncf/soutchatinternal/repository"
)

type goldRepository struct {
	*repository.Repository
}

func NewGoldRepository(r *repository.Repository) repository.GoldRepository {
	return &goldRepository{
		Repository: r,
	}
}

func (r *goldRepository) GetGoldType(ctx context.Context, typ int) (m *model.GoldType, err error) {
	err = r.DB(ctx).Model(&model.GoldType{}).Where("typ = ?", typ).First(&m).Error
	return
}

func (r *goldRepository) GetGoldFlowRecord(ctx context.Context, uid uint64, id int64) (m []*model.GoldRecord, err error) {
	err = r.DB(ctx).Model(&model.GoldRecord{}).Where("uid = ? and id < ?", uid, id).Order("id desc").Find(&m).Error
	return
}

func (r *goldRepository) GetDiamondFlowRecord(ctx context.Context, uid uint64, id int64) (m []*model.DiamondRecord, err error) {
	err = r.DB(ctx).Model(&model.DiamondRecord{}).Where("uid = ? and id < ?", uid, id).Order("id desc").Find(&m).Error
	return
}
